home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / technote / tchntstc.sit / Technical Notes Stack 3.2.1 / Technical Notes Stack 3.2.1 / card_71982.txt < prev    next >
Encoding:
Text File  |  1990-01-08  |  4.5 KB  |  84 lines

  1. -- card: 71982 from stack: in.1
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2711
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 9
  9. ----- text -----
  10. #259:    Old Style Colors
  11.  
  12. Written by:    Rich ΓÇ£I See ColorsΓÇ¥ Collyer & Byron Han             October 1989
  13.  
  14. This Technical Note covers limitations of the original Macintosh color model
  15. (eight-color) which are not covered in Inside Macintosh, Volume I-173, QuickDraw.
  16. _______________________________________________________________________________
  17.  
  18. QuickDraw has always been able to deal with color, just on a very limited basis.  Most applications have not made use of this feature, since Color QuickDraw-based Macintoshes come with a better color model.  There are, however, a few nice features which come with the old style color model.  With the old style colors, it is easy to print color on an ImageWriter with a color ribbon.  Another advantage is that developers do not have to write special-case code depending upon whether or not a machine has Color QuickDraw.
  19.  
  20. Now that you are ready to convert to the old style colors, there are a few things you should know about which do not work with old style colors.  This Note covers the limitations of using old style colors, as well as the best ways to work around these limitations.
  21.  
  22.  
  23. Limitations
  24.  
  25. The most obvious limitation is that of only eight colors:  black, white, red, green, blue, cyan, yellow, and magenta.  This limitation is only a problem if you want to produce a color-intensive application; if this describes your application, then you need not read any further in this Note.
  26.  
  27. The next limitation is that off-screen buffers are not very useful.  You can draw into off-screen buffers, but there is no way to get the colors back from the buffer.  This leads into the next limitation, which is that _CopyBits cannot copy more than one color at a time.
  28.  
  29. When you call _CopyBits from an off-screen buffer to your window, you need to set the forecolor to the color you want to copy before calling _CopyBits (i.e., to copy a red object, call _ForeColor(redColor)).  Now when you copy the object, you can only copy one color.  If you copy different colored objects at one time, then you have a problem.  The result of a multicolored copy is that all objects copy in the same color, that of the foreground.
  30.  
  31. It is possible to work with an off-screen buffer and the old style colors, but it requires a lot of extra work.  Unless the objects are really complex, then it is probably easier to just draw the objects directly into your window.
  32.  
  33. One other limitation does exist.  Consider the following code sample.  One would assume that this sample would work at all times.
  34.  
  35.     SetPort (myPort);
  36.     savedFG := myPort^.fgColor;
  37.     ForeColor (redColor);            {or any other color}
  38.  
  39.     {...drawing takes place here...}
  40.  
  41.     ForeColor (savedFG);
  42.  
  43. Surprise.  It doesnΓÇÖt always work.  The saved value for the fgColor field of the grafPort is not a classic QuickDraw color if the grafPort is actually a CGrafPort.  If dealing with a CGrafPort, the fgColor field actually contains the foreground colorΓÇÖs entry in the color table, so the second call to
  44. _ForeColor really messes things up.
  45.  
  46. The proper way to set and reset the foreground color with classic QuickDrawΓÇÖs
  47. _ForeColor call is as follows:
  48.  
  49.     SetPort (myPort);
  50.     savedFG := myPort^.fgColor;
  51.     ForeColor (redColor);            {or any other color}
  52.  
  53.     {...drawing takes place here...}
  54.  
  55.     myPort^.fgColor := savedFG;      {manually stuff the old fgColor back}
  56.     If (32BQD = TRUE) Then
  57.         PortChanged (myPort);
  58.  
  59. This Note also applies to the routine _BackColor.
  60.  
  61.  
  62. What Works
  63.  
  64. The easiest way to work with these limited colors is to use pictures.  When you draw the images, you should draw into a picture.  Then when you want to draw the images into your window or to a printer, call _DrawPicture.  Pictures work well with the old style colors, and you donΓÇÖt need to worry about making sure that the forecolor is current when you draw into your window.
  65.  
  66. Once you have the picture, you can use it to draw into the screen or to the printer port.  You can also set the WindowRecords windowPic to equal your PictureHandle so updates are handled by the Window Manager.
  67.  
  68.  
  69. Further Reference:
  70. _______________________________________________________________________________
  71.   ΓÇó  Inside Macintosh, Volume I-173, QuickDraw
  72.  
  73.  
  74. -- part contents for background part 2
  75. ----- text -----
  76. 259
  77.  
  78. -- part contents for background part 7
  79. ----- text -----
  80. Old Style Colors
  81.  
  82. -- part contents for background part 113
  83. ----- text -----
  84. QuickDraw